package com.dic.common.valid;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.HashSet;
import java.util.Set;

/**
 * @author ：leeliang
 * @date ：Created in 2020/11/8 16:30
 * @description：
 * @modified By：
 * @version: $
 */
public class StatusListConstraintValidator implements ConstraintValidator<StatusList,Integer> {

    private Set set = new HashSet();
    @Override
    public void initialize(StatusList constraintAnnotation) {
        int[] vals = constraintAnnotation.vals();
        for (int num:vals
             ) {
            set.add(num);
        }
    }

    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext context) {
        return set.contains(value);
    }
}
